package com.hgw.Demo04_CreateInterator.LinkedListDemo;


import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

/**
 * Data time:2021/12/18 13:20
 * StudentID:2019112118
 * Author:hgw
 * Description:
 */
public class IteratorDemo {
    public static void process(Collection c) {
        Iterator i = c.iterator();     // 创建迭代器对象

        // 通过迭代器遍历聚合对象
        while (i.hasNext()) {
            System.out.println(i.next().toString());
        }
    }

    public static void main(String[] args) {
        Collection person;
        person = new ArrayList();   // 创建一个 ArrayList 类型的聚合对象
        person.add("张无忌");
        person.add("小龙女");
        person.add("令狐冲");
        person.add("韦小宝");
        person.add("袁紫衣");
        person.add("小龙女");

        process(person);
    }
}
